// import 'dayjs/locale/zh-cn';
// import 'dayjs/locale/ar-sa';
import { i18n } from './locales/setupI18n';
import { localeSetting } from '@/settings/localeSettings';
import { RouteRecordRawNew } from '@/store/type/index.d';
import { useRouteStore } from '@/store/modules/index';
import { storeToRefs } from 'pinia';
import { useRoute } from 'vue-router';
// 项目初始化
export const useAppInitHooks = () => {
  const route = useRoute();
  const { routeList, defaultMenuItem } = storeToRefs(useRouteStore());
  const current = ref<string[]>(['']);
  watch(
    () => route.path,
    (val: string) => {
      if (val.match(/\/([^\/]+)/g)) {
        current.value[0] = (val.match(/\/([^\/]+)/g) as RegExpMatchArray)[0];
      }
    },
    { deep: true, immediate: true },
  );
  // 把数据存在pinia中
  const menuItemClick = (item: RouteRecordRawNew) => {
    defaultMenuItem.value = item;
  };
  // 退出登录
  const exitLogin = () => {};
  return {
    current,
    routeList,
    menuItemClick,
    exitLogin,
  };
};

// 关于国际化的hooks
export const useAppI18Hooks = () => {
  const { locale } = localeSetting;
  const getAntdLocale = (i18n?.global?.getLocaleMessage(locale) as any)?.antdLocale;

  return {
    getAntdLocale,
  };
};
